<!DOCTYPE html>
<?php
$frist=!count($_POST);
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        if($frist){
           
        if($_GET["id"]){
         $uid=(int)$_GET["id"];
        //要求用户id必须是数字
         if($uid){
        $hostname="127.0.0.1";
        $username="root";
        $password="123456";
        $database="myshop";
        $connect=mysqli_connect($hostname, $username,
                $password, $database);
        //设置连接的字符集
        mysqli_set_charset($connect, "utf-8");
        if($connect){
            $sqlstring="select * from userinfos where uid=${uid}";
            $result=mysqli_query($connect, $sqlstring);
            //mysqli_num_rows 获得查询结果集中有多少条数据 
           if( mysqli_num_rows($result)==0){
               echo "参数错误";
           }else{
               $row= mysqli_fetch_array($result);
               ?>
         <h1>添加用户</h1>
        <form action="edituser.php" method="post"  enctype="multipart/form-data">
            账户：<input type="text" name="username" value="<?php echo $row["username"];?>"/><br/>
            密码：<input type="password" name="upwd" value="<?php echo $row["upasswd"];?>"/><br/>
            性别：<select name="sex">
                <option <?php echo $row["sex"]=='男'?"selected=\"selected\"":"";?> >男</option>
                <option <?php echo $row["sex"]=='女'?"selected=\"selected\"":"";?> >女</option>
            </select>
            <br/>
            年龄：
            <select name="age">
                <?php
                for($index=18;$index<=100;$index++){
                    if($index==$row["age"]){
                        echo "<option selected=\"selected\">$index</option>";
                    }else{
                         echo "<option>$index</option>";
                    }
                    
                }
                ?>
            </select>
            <br/>
            原来头像：<img src="<?php echo $row["pic"];?>" style="height: 100px;width: 100px;" />
            <br/>
            更改头像：<input type="file" name="myimg"/><br/>
            <input type="submit" value="确定"/>
            <input type="reset" value="取消"/>
        </form>
        <?php
           }
        }
         }else{
             echo "参数错误";
         }
        }
            
            ?>
       
        
        <?php 
        }
        ?>
    </body>
</html>
